<template> 
  <el-card class="form-container" shadow="never">
    <el-form :model="homeAdvertise"
             :rules="rules"
             ref="homeAdvertiseFrom"
             label-width="150px"
             size="small" class="demo-ruleForm">

      <el-form-item label="推广成功奖励积分：">
        <el-input v-model="homeAdvertise.integration" style="width: 200px"></el-input>
        <span style="margin-left: 20px">积分</span>
      </el-form-item>


      <el-form-item label="推广成功奖励金额：">
        <el-input v-model="homeAdvertise.money" style="width: 200px"></el-input>
        <span style="margin-left: 20px">元</span>
      </el-form-item>
      

      <el-form-item label="启用：">
        <el-radio-group v-model="homeAdvertise.status">
          <el-radio :label="0">是</el-radio>
          <el-radio :label="1">否</el-radio>
        </el-radio-group>
      </el-form-item>
      
      
      <el-form-item>
        <el-button type="primary" @click="onSubmit('homeAdvertiseFrom')">提交</el-button>
        <!-- <el-button v-if="!isEdit" @click="resetForm('homeAdvertiseFrom')">重置</el-button> -->
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script>
  import SingleUpload from '@/components/Upload/singleUpload'
  import {saveextension, extensionList, updataextension} from '@/api/homeAdvertise'
  const defaultHomeAdvertise = {
    integration: 0,
    money: 0,
    status:1
  };
  export default {
    name: 'HomeAdvertiseDetail',
    components:{SingleUpload},
    props: {
      isEdit: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        homeAdvertise: {
          integration: '',
          money: '',
          status:1
        },
        rules: {
          integration: [
            {required: true, message: '请输入数字', trigger: 'blur'}
          ],
          money: [
            {required: true, message: '请输入数字', trigger: 'blur'}
          ]
        }
      }
    },
    created(){
      if (this.isEdit) {
        extensionList(this.$route.query.id).then(response => {
          this.homeAdvertise = response.data;
        });
      }else{
        this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
      }
    },
    methods: {
      onSubmit(formName) {
        
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$confirm('是否提交数据', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              if (this.isEdit) {
                updataextension(this.homeAdvertise).then(response => {
                  this.$refs[formName].resetFields();
                  this.$message({
                    message: '修改成功',
                    type: 'success',
                    duration:1000
                  });
                  this.$router.back();
                });
              } else {
                saveextension(this.homeAdvertise).then(response => {
                  this.$refs[formName].resetFields();
                  this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
                  this.$message({
                    message: '提交成功',
                    type: 'success',
                    duration:1000
                  });
                });
              }
            });

          } else {
            this.$message({
              message: '验证失败',
              type: 'error',
              duration:1000
            });
            return false;
          }
        });
      },
      // resetForm(formName) {
      //   this.$refs[formName].resetFields();
      //   this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
      // }
    }
  }
</script>
<style scoped>
  .input-width {
    width: 70%;
  }
</style>


